<?php
namespace App\Http\Controllers\Client\Activity\Talent;

use App\Http\Controllers\ClientController;
use App\Models\Tools\AliOss;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class WinnerConsumeBeforeController extends ClientController
{

    public function index()
    {

        $all = $this->all;
        $act_id = $all['act_id'];

        try{

            // 查询是否是当前活动的中奖人
            $we_id = DB::table('lottery_draw_detail')->where('act_id','=',$act_id)->value('we_id');
            if($we_id !== $this->we_id){
                return $this->setReturnJson(1,'您不是当前活动的中奖人');
            }

            // 查询店铺奖品详情
            $result = DB::table('lottery_activity as la')
                ->leftJoin('lottery_goods as lg','la.goods_id','=','lg.goods_id')
                ->leftJoin('shop','la.shop_id','=','shop.shop_id')
                ->leftJoin('dict_area as da','shop.district','=','da.id')
                ->leftJoin('lottery_draw_detail as ldd','la.act_id','=','ldd.act_id')
                ->leftJoin('lottery_users_draw as lud','ldd.participate_id','=','lud.participate_id')
                ->where('la.act_id','=',$act_id)
                ->select('la.goods_id','lg.goods_name','lg.price','lg.detail','shop.shop_name','shop.address','da.short_name','shop.contact_man','shop.contact_phone','lud.code','la.draw_time')
                ->first();
            $result = json_decode(json_encode($result), true);
            $result['consume_end_time'] = date("Y-m-d",strtotime($result['draw_time'] ."+14 day"));
            $result['overtime'] = strtotime($result['consume_end_time']) < strtotime(date("Y-m-d"));

        } catch (\Exception $e) {
            Log::error(WinnerConsumeBeforeController::class, ['msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
            return $this->setReturnJson(-1, '查询失败，请稍后重试');
        }
        return $this->setReturnJson(0,'success',$result);

    }

}
